package cn.stylefeng.guns.modular.lx.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.lx.entity.LxOrderWrh;
import cn.stylefeng.guns.modular.lx.mapper.LxOrderWrhMapper;
import cn.stylefeng.guns.modular.lx.model.params.LxOrderWrhParam;
import cn.stylefeng.guns.modular.lx.model.result.LxOrderWrhResult;
import  cn.stylefeng.guns.modular.lx.service.LxOrderWrhService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2023-12-04
 */
@Service
public class LxOrderWrhServiceImpl extends ServiceImpl<LxOrderWrhMapper, LxOrderWrh> implements LxOrderWrhService {

    @Override
    public void add(LxOrderWrhParam param){
        LxOrderWrh entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(LxOrderWrhParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(LxOrderWrhParam param){
        LxOrderWrh oldEntity = getOldEntity(param);
        LxOrderWrh newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public LxOrderWrhResult findBySpec(LxOrderWrhParam param){
        return null;
    }

    @Override
    public List<LxOrderWrhResult> findListBySpec(LxOrderWrhParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(LxOrderWrhParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(LxOrderWrhParam param){
        return param.getOrderDdbh();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private LxOrderWrh getOldEntity(LxOrderWrhParam param) {
        return this.getById(getKey(param));
    }

    private LxOrderWrh getEntity(LxOrderWrhParam param) {
        LxOrderWrh entity = new LxOrderWrh();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
